
pub fn retire_time(time: &str, tp: &str) -> String {
    // 解析输入的年月
    let parts: Vec<&str> = time.split('-').collect();
    if parts.len() != 2 {
        return "Invalid date format".to_string();
    }
    
    let birth_year = parts[0].parse::<i32>().unwrap_or(0);
    let birth_month = parts[1].parse::<i32>().unwrap_or(0);

    // 根据职工类型确定基础退休年龄和延迟退休政策
    let (base_age, additional_months) = match tp {
        "男职工" => {
            let base = 60;
            if birth_year >= 1965 && birth_year <= 1976 {
                let months = calculate_additional_months(birth_year, birth_month, 1965, 4);
                (base, months + 1)
            } else if birth_year > 1976 {
                (base, 36)
            } else {
                (base, 0)
            }
        },
        "原法定退休年龄55周岁女职工" => {
            let base = 55;
            if birth_year >= 1970 && birth_year <= 1981 {
                let months = calculate_additional_months(birth_year, birth_month, 1970, 4);
                (base, months + 1)
            } else if birth_year > 1981 {
                (base, 36)
            } else {
                (base, 0)
            }
        },
        "原法定退休年龄50周岁女职工" => {
            let base = 50;
            if birth_year >= 1975 && birth_year <= 1984 {
                let months = calculate_additional_months(birth_year, birth_month, 1975, 2);
                (base, months + 1)
            } else if birth_year > 1984 {
                (base, 60)
            } else {
                (base, 0)
            }
        },
        _ => (0, 0),
    };

    // 计算额外年份和剩余月份
    let additional_years = additional_months / 12;
    let remaining_months = additional_months % 12;

    // 计算最终退休年月
    let mut retire_year = birth_year + base_age + additional_years;
    let mut retire_month = birth_month + remaining_months;
    
    // 处理月份进位
    if retire_month > 12 {
        retire_month -= 12;
        retire_year += 1;
    }

    // 计算精确退休年龄
    let exact_age = base_age as f64 + (additional_months as f64 / 12.0);

    // // 判断年龄是否为整数
    // let age_str = if (exact_age * 100.0).round() % 100.0 == 0.0 {
    //     format!("{}", exact_age as i32)
    // } else {
    //     format!("{:.2}", exact_age)
    // };
    // 按照要求格式化输出字符串
    format!(
        "{:04}-{:02},{},{}",
        retire_year,
        retire_month,
        if (exact_age * 100.0).round() % 100.0 == 0.0 {
            format!("{}", exact_age as i32)
        } else {
            format!("{:.2}", exact_age)
        },
        additional_months
    )
}

fn calculate_additional_months(year: i32, month: i32, start_year: i32, interval: i32) -> i32 {
    let months_from_start = (year - start_year) * 12 + month - 1;
    months_from_start / interval
}
